﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Obra.Api;

namespace Obra.SmugMug.Api
{
    public partial class Image
    {
        private readonly ImageContract image;
        private readonly ISession session;
        private readonly ISmugMugClient client;

        /// <summary>
        /// c-tor
        /// </summary>
        /// <param name="image">
        /// ImageContract returned by SmugMug, which this class proxies.
        /// </param>
        /// <param name="session">
        /// The current sesssion identifier with SmugMug.
        /// </param>
        /// <param name="client">
        /// Client used to access SmugMug.
        /// </param>
        public Image(
            ImageContract image,
            ISession session,
            ISmugMugClient client)
        {
            this.image = image;
            this.session = session;
            this.client = client;
        }

        /// <summary>
        /// This class serves as a proxy for the underlying REST response from
        /// smugmug.com.
        /// </summary>
        internal ImageContract ImageContract
        {
            get { return image; }
        }

        /// <summary>
        /// WCF interface for interacting with smugmug.com.
        /// </summary>
        internal ISmugMugClient SmugMug
        {
            get { return client; }
        }

        /// <summary>
        /// Get the album ID of this image, or move this image to a new album.
        /// </summary>
        public int AlbumId
        {
            get { return this.ImageContract.Album.Id; }
            set { this.SmugMug.ChangeImageAlbum(this.session.SessionId, this.ImageContract.Id, value); }
        }

        private ImageExif imageExif;

        /// <summary>
        /// Get the Image EXIF information.
        /// </summary>
        public ImageExif Exif
        {
            get 
            {
                if (this.imageExif == null)
                {
                    this.imageExif = this.SmugMug.GetImageExif(this.session.SessionId, this.ImageContract.Id); 
                }

                return this.imageExif;
            }
        }
    }
}